#coding=utf-8

import os
import ConfigParser

class config(object) :
    """""""""""""""""""""""""""""""""""""""""""""
     # 配置文件解析
     # @class
     # @copyright Copyright (c) 2010, pe-dev. inc
     # @author alone <phperlon@gmail.com>
     # @license
    """""""""""""""""""""""""""""""""""""""""""""

    def __init__(self,conf_file='../conf/config.conf') :
        """""""""""""""""""""""""""""""""""""""
         # 初始化配置解析
         #
         # @author   alone <phperlon@gmail.com>
         # @param    
         # @return   
         # @todo     
        """""""""""""""""""""""""""""""""""""""
        real_path = os.path.realpath(os.path.join(os.path.dirname(__file__),conf_file))
        if os.path.isfile(real_path) :
            self.config = ConfigParser.ConfigParser()
            fp = open(real_path)
            self.config.readfp(fp)
            fp.close()
        else :
            print 'config file don\'t exist(%s)' % real_path
            os._exit(0)

    def setting(self) :
        """""""""""""""""""""""""""""""""""""""
         # 获取所有section配置项
         #
         # @author   alone <phperlon@gmail.com>
         # @param    
         # @return   
         # @todo     
        """""""""""""""""""""""""""""""""""""""
        self.setting = {}
        for item in self.config.sections() :
            self.setting[item] = self.getConf(item)
        return self.setting

    def getConf(self,section) :
        """""""""""""""""""""""""""""""""""""""
         # 获取某个section配置项
         #
         # @author   alone <phperlon@gmail.com>
         # @param    string section 配置项名称
         # @return   
         # @todo     
        """""""""""""""""""""""""""""""""""""""
        setting = {}
        for k,v in self.config.items(section) :
            setting[k] = v
        return setting